package com.moneywelcome.orderassembly.apiImpl;

import com.moneywelcome.annnotation.RedisAnnotation;
import com.moneywelcome.orderassembly.service.GoldCommentService;
import com.moneywelcome.orderassembly.service.GoldReplyService;
import com.moneywelcome.orderfacade.DiscussApi;
import com.moneywelcome.orderfacade.dto.CommentDto;
import com.moneywelcome.orderfacade.dto.ReplyDto;
import com.moneywelcome.orderfacade.vo.CommentVo;
import com.moneywelcome.orderfacade.vo.ReplyVo;
import com.moneywelcome.results.PageResult;
import com.moneywelcome.results.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@Api(tags = "讨论区服务")
public class DiscussApiImpl implements DiscussApi {
    @Autowired
    private GoldCommentService gcs;
    @Autowired
    private GoldReplyService grs;
    @Override
    @RedisAnnotation
    public Result<PageResult<CommentDto>> loadComment(String goldId) {
        log.info("加载黄金{}的评论",goldId);
        return Result.success(gcs.loadComment(goldId));
    }
//@GlobalTransactional
    @Override
    @RedisAnnotation(read = false,refresh = "com.moneywelcome.orderassembly.apiImpl.DiscussApiImpl.loadComment")
    public Result<CommentDto> comment(CommentVo commentVo) {
        log.info("发表评论{}",commentVo);
        return Result.success(gcs.create(commentVo));
    }
//    @GlobalTransactional
    @Override
    @RedisAnnotation(read = false,refresh = "com.moneywelcome.orderassembly.apiImpl.DiscussApiImpl.loadComment")
    public Result<ReplyDto> reply(ReplyVo replyVo) {
        log.info("发表回复{}",replyVo);
        return Result.success(grs.create(replyVo));
    }
}
